<include file="public@header" />
<link rel="stylesheet" type="text/css" href="__STATIC__/layui/css/layui.css">
</head>
<body>
	<div class="wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:url('area_manager/index')}">区域列表</a></li>
			<li class="active"><a>编辑区域</a></li>
		</ul>
		<form method="post" class="form-horizontal js-ajax-form margin-top-20 layui-form" action="{:url('area_manager/edit')}">
			<div class="form-group">
				<label class="col-sm-2 control-label">
					<span class="form-required">*</span>区域负责人
				</label>
				<div class="col-md-3 col-sm-6">
					<select class="form-control" name="staff_id" lay-search="">
			          	<option value="">请选择员工</option>
			          	<foreach name="staff_list" item="vo">
			          		<option value="{$vo.id}" <if $vo.id == $row.staff_id>selected</if> >{$vo.name}</option>
			          	</foreach>
			        </select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">
					<span class="form-required">*</span>管理区域
				</label>
				<div class="col-md-6 col-sm-10">
					<label class="form-inline">
						<select class="form-control" name="province_id" id="province" lay-ignore>
	                        <option value="">请选择省</option>
	                    </select>
	                </label>
	                <label class="form-inline">
	                    <select class="form-control" name="city_id" id="city" lay-ignore>
	                        <option value="">请选择市</option>
	                    </select>
	                </label>
                    <label class="form-inline">
	                    <select class="form-control" name="area_id" id="area" lay-ignore>
	                        <option value="">请选择区</option>
	                    </select>
	                </label>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<input type="hidden" name="id" value="{$row.id}">
					<button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
				</div>
			</div>
		</form>
	</div>
	<script src="__STATIC__/js/admin.js"></script>
	<script src="__STATIC__/layui/layui.js"></script>
	<script type="text/javascript">
		function get_region_list(parentid,obj)
        {
            $.ajax({
                type:'get',
                url:'{:url("staff/get_region_list")}',
                data:{parentid:parentid},
                success:function(res){
                    var html = '<option value="">请选择</option>';
                    var json = eval(res.data);
                    for (var key in json) {
                    	html += '<option value="'+json[key].id+'" data-id="'+json[key].id+'">'+json[key].areaname+'</option>';
                    }
                    $('#'+obj).html(html);
                }
            });
        }

        get_region_list(0,'province');

        $('#province').change(function(){
            var id = $(this).find("option:selected").attr('data-id');
            get_region_list(id,'city');
            $('#area').html('<option value="">请选择</option>');
        });

        $('#city').change(function(){
            var id = $(this).find("option:selected").attr('data-id');
            get_region_list(id,'area');
        });

        setTimeout(function(){ $('#province').val('{$row.province_id}').trigger('change'); }, 200);
        setTimeout(function(){ $('#city').val('{$row.city_id}').trigger('change'); }, 400);
        setTimeout(function(){ $('#area').val('{$row.area_id}'); }, 600);

        layui.use(['form'], function(){
			var form = layui.form;
		});
	</script>
</body>
</html>